package com.qylm.lawyermanager.dongao.controller;

import com.qylm.lawyermanager.dongao.entity.Lawyer;
import com.qylm.lawyermanager.dongao.service.allLawyerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 律师控制器
 * @author xuerudan
 * @version 1.0
 */
@Controller
public class AllLawyerController {
    @Autowired
    allLawyerService allLawyerService;
    @RequestMapping("/modify")
    public String modifyLawyer(Lawyer lawyer){
        allLawyerService.modifyLawyer(lawyer);
        return "../static/success";
    }

    @RequestMapping("/getLawyer")
    public String getLawyerById(Model model,int lawyerid){
        Lawyer lawyer= allLawyerService.findLawyerById(lawyerid);
        //把查询得到的lawyer对象保存起来，传递到网页上
        model.addAttribute("lawyer",lawyer);
        return "../static/modifyLawyer";
    }

    @RequestMapping("/del")
    public String delLawyer(int lawyerid){
        allLawyerService.removeLawyer(lawyerid);
        return "../static/success";
    }
    @RequestMapping("/show")
    public String showLawyer(Model model){
        List<Lawyer> lawyerList= allLawyerService.findLawyer();
        //把lawyerlist传递到网页
        model.addAttribute("lawList",lawyerList);
        //displayLawyer代表网页
        return "../static/displayLawyer";
    }
    @RequestMapping("/addLawyer")
    public String addLawyer(Lawyer lawyer){
        allLawyerService.addLawyer(lawyer);
        //success代表网页
        return "../static/success";

    }

}